﻿<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\web\View;
use backend\models\service\AdminService as Admin;
use backend\models\service\Chapter;
?>

<div class="pushactivity-form">
    <article class="center">
        <?php
        $form = ActiveForm::begin([
                    'fieldConfig' => [
                        'template' => '<div style="height:50px;"><div class="col-xs-3">{label}</div><div class="col-xs-9">{input}{error}</div></div>',
                    ]
        ]);
        ?>
        <?=
        $form->field($model, 'op_id')->dropDownList(Admin::items('2'), [
            'prompt' => '请选择合作方',
            'onchange' => '
                $.ajax({
                    type:"post",
                    url:"/admin/get-channel-nums",
                    data:{pid:$(this).val(),type:3},
                    success:function(msg){
                        $(".c_name").empty();
                        var str = "<option value=>请选择</option>"+msg;
                        $(".c_name").append(str);
                    }
                });
            '
        ])->label('选择合作方')
        ?>
        <input type = "hidden" name = "TweetService[novel_id]" id = "tweetservice-novel_id" value = "<?php echo $data['novel_id'];?>">
        <input type = "hidden" name = "TweetService[novel_name]" id = "tweetservice-novel_name" value = "<?php echo $data['novel_title'];?>">
        <input type = "hidden" name = "TweetService[op_name]" id = "tweetservice-op_name" value = "">
        <?= $form->field($model, 'channel_id')->dropDownList(Admin::items('username'), ['prompt' => '请选择', 'style' => 'width:120px' ,'class'=>'c_name'])->label('选择渠道') ?>
        <input type = "hidden" name = "TweetService[channel_name]" id = "tweetservice-channel_name" value = "">
        <?= $form->field($model, 'tweet_sn',['template'=>'<div style="height:50px;"><div class="col-xs-3">{label}</div><div class="col-xs-">{input}{error}</div><div class="col-xs-4" style="margin-top:5px;">自动生成</div></div>'])->label('推广编号')->hiddenInput(['value' => 1]) ?>
        <?= $form->field($model, 'chapter_id')->dropDownList(Chapter::items($id), ['prompt'=>'请选择','style'=>'width:120px'])->label('推文章节') ?>
        <?php $model->platform = 1; ?>
        <?= $form->field($model, 'platform')->textInput()->radioList(['1' => '微信', '2' => '微博', '3' => 'APP', '4' => '其他'])->label('推文平台') ?>
        <?= $form->field($model, 'is_force_focus_wechat')->dropDownList(['0' => '否', '1' => '是'])->label('是否强制关注微信公共号') ?>
        <?= $form->field($model, 'is_force_focus_chapter')->dropDownList(['0' => '否', '1' => '是'])->label('强制关注起始章节') ?>
        <?= $form->field($model, 'key_words')->textArea(['rows' => 3])->label('微信回复关键字') ?>
        <?= Html::submitButton('保存创建', ['class' => 'extend btn btn-primary', 'name' => 'submit-button']) ?>
        <?php ActiveForm::end(); ?>

    </article>
</div>
<script>
    $("#tweetservice-op_id").change(function(){
        var h = $(this).find("option:selected").text();
        $("#tweetservice-op_name").val(h);
    });
    $("#tweetservice-channel_id").change(function(){
        var h = $(this).find("option:selected").text();
        $("#tweetservice-channel_name").val(h);
    });
 $(function(){
    $(".extend").click(function(){
        var username = $("#tweetservice-op_id").val(); 
        console.log(username);
        if(username == ''){
            alert('合作方账号不能为空');
            return false;
        }
        var c_name = $('#tweetservice-channel_id').val();
        console.log(c_name);
        if(c_name == ''){
            alert('渠道名称不能为空');
            return false;
        }
        var chapter = $('#tweetservice-chapter_id').val();
        console.log(chapter);
        if(chapter == ''){
            alert('推文章节不能为空');
            return false;
        }
    })
});
</script>